package com.lmq

import org.apache.spark.sql.Column
import org.apache.spark.sql.functions.{col, udf}

import java.text.SimpleDateFormat
import java.util.Date
import scala.collection.mutable

/**
 * TODO:
 *     user defined function
 */
class utils  extends  Serializable {
  def timeStr2Tsp(timeString:String):Double={
//    val format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    val format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
//    val time = "2018-09-29 16:39:00"
//    println("now is "+timeString.substring(0,19))
    val date = format.parse(timeString.substring(0,19))
    //日期转时间戳（毫秒）
    date.getTime


  }

  def Tsp2Time(Tsp:Double):String = {
    val fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    val t: String = fm.format(new Date(Tsp.toLong))
    t.substring(0,10)
  }

  def toStrFnc(sep:String) = udf((x:mutable.WrappedArray[AnyVal])=>x.mkString(sep))




}

